package com.atguigu;

import io.minio.*;
import io.minio.errors.*;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MinioTest {
    public static void main(String[] args) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        String endPoint = "http://192.168.6.100:9000";
        MinioClient minioClient = MinioClient.builder().endpoint(endPoint)
                .credentials("minioadmin", "minioadmin")
                .build();
        boolean b = minioClient.bucketExists(BucketExistsArgs.builder().bucket("apartment").build());
        if (!b) {
            minioClient.makeBucket(MakeBucketArgs.builder().bucket("apartment").build());

            String policy = """
                    {
                                              "Statement" : [ {
                                                "Action" : "s3:GetObject",
                                                "Effect" : "Allow",
                                                "Principal" : "*",
                                                "Resource" : "arn:aws:s3:::hello-minio/*"
                                              } ],
                                              "Version" : "2012-10-17"
                                            }
                    """;
            minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket("apartment").config(policy).build());
        }
        minioClient.uploadObject(UploadObjectArgs.builder().bucket("apartment")
                .object("6.jpg")
                .filename("C:\\Users\\yangliu\\Desktop\\6.jpg").build());

    }
}
